<template>
  <div>
    <el-descriptions title="宿舍信息">
      <el-descriptions-item label="您的宿舍为">{{ roomName }}</el-descriptions-item>
    </el-descriptions>
    <br>
    <el-descriptions title="宿舍成员">
    </el-descriptions>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          prop="stuName"
          label="姓名"
          width="180">
      </el-table-column>
      <el-table-column
          prop="stuNo"
          label="学号"
          width="180">
      </el-table-column>
      <el-table-column
          prop="email"
          label="邮箱">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "Result",
  data() {
    return {
      roomName: '',

      tableData: [
        // {
        //   stuName: '',
        //   stuNo: '',
        //   email: ''
        // },
        // {
        //   stuName: '',
        //   stuNo: '',
        //   email: ''
        // },
        // {
        //   stuName: '',
        //   stuNo: '',
        //   email: ''
        // },
        // {
        //   stuName: '',
        //   stuNo: '',
        //   email: ''
        // }
        ]
    }
  },
  methods: {},
  created: function () {

    let token = localStorage.getItem("token")
    axios.defaults.withCredentials = true
    document.cookie = 'access-token' + token

    let orderId = localStorage.getItem("orderId")
    let param = {
      "orderId": orderId,
    }

    this.$axios.post("http://localhost:8090/dorm/result", param)
        .then(res => {
          if (res.data.code == 200) {
            //alert(res.data.result)
            this.roomName = res.data.result.roomName
            console.log("响应结果为...")
            console.log(res.data.result.resultMateDtoList)

            for (let i = 0; i < res.data.result.resultMateDtoList.length; i++) {
              let data = {
                stuName: res.data.result.resultMateDtoList[i].stuName,
                stuNo: res.data.result.resultMateDtoList[i].stuNo,
                email: res.data.result.resultMateDtoList[i].email,
              }
              this.tableData.push(data)
              // this.tableData[i].stuName = res.data.result.resultMateDtoList[i].stuName
              // this.tableData[i].stuNo = res.data.result.resultMateDtoList[i].stuNo
              // this.tableData[i].email = res.data.result.resultMateDtoList[i].email
            }


          } else if (res.data.code == 500) {
            alert(res.data.message)
          } else {
            alert("您尚未选宿舍,请选择在线抢宿舍!")
          }
        })
  }
}
</script>

<style scoped>

</style>